project(pyVascular CXX CUDA)

include_directories(
        VascularMain/include
        SubModule/CNFD/include
        SubModule/Hilditch/include
        SubModule/Intersection/include
        SubModule/CTBD/include
)

find_package(NumpyMatConvert)
find_package(SegCudaCommon)
link_libraries(
        NumpyMatConvert::NumpyMatConvert
        SegCudaCommon::SegCudaCommon
)

# 由于依赖关系太多，进行手动编译
add_library(${PROJECT_NAME}Intersection STATIC
        SubModule/Intersection/include/intersection.h SubModule/Intersection/src/intersection.cpp)
# cuda和c++多线程冲突
add_library(${PROJECT_NAME}CNFD STATIC
        SubModule/CNFD/src/CNFD.cu SubModule/CNFD/include/CNFD.cuh)
set_target_properties(${PROJECT_NAME}CNFD
        PROPERTIES
        CUDA_SEPARABLE_COMPILATION ON  # cu will build by nvcc
        POSITION_INDEPENDENT_CODE ON  # for split __device__ into multi *.a
#        CUDA_RESOLVE_DEVICE_SYMBOLS ON # ask for relink symbol
        LINKER_LANGUAGE CXX
)

set(SOURCE_LIST
        VascularMain/src/vascular.cpp
        SubModule/Hilditch/src/hilditch.cpp
        SubModule/CTBD/src/CTBD.cpp

        VascularMain/include/vascular.h
        SubModule/Hilditch/include/hilditch.h
        SubModule/CTBD/include/CTBD.h
        wrapper/vascular_wrapper.cpp
)
set(SOURCE_DIR VascularMain/include)
set(PUBLIC_HEADER_LIST VascularMain/include/vascular.h)
set(BUILD_FOR_PY ON)

SegModuleBuild(
        ${PROJECT_NAME}
            "${SOURCE_LIST}" "${SOURCE_DIR}"
            "${PUBLIC_HEADER_LIST}" ${BUILD_FOR_PY} ON OFF
)

#add_executable(${PROJECT_NAME}
#        SubModule/Intersection/src/intersection.cpp
#        SubModule/Intersection/include/intersection.h
#
##        SubModule/CTBD/include/CTBD.h
##        SubModule/CTBD/src/CTBD.cpp
#)

target_link_libraries(${PROJECT_NAME}
        PRIVATE
            ${PROJECT_NAME}Intersection
            ${PROJECT_NAME}CNFD
)

#set_target_properties(${PROJECT_NAME}
#        PROPERTIES
#        CUDA_SEPARABLE_COMPILATION ON
#        CUDA_RESOLVE_DEVICE_SYMBOLS ON
#        POSITION_INDEPENDENT_CODE ON
#)

